package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.GetTradesEvent;
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.TradeMarkVO;
	import net.optix.ip.vo.TradeSecretVO;
	
	public class GetTradesCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:GetTradesEvent = GetTradesEvent( event );
			
			var delegate:TradeMarkDelegate = new TradeMarkDelegate();     
			delegate.getTradesInformation( this,myEvent.clientID );
			
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{trace(event.result);
			try
			{
				var result:XML		=	event.result.tradeMarks[0];
				var marks:ArrayCollection	=	new ArrayCollection();
				for(var i:int=0; i<result.Data.length(); i++)
				{
					marks.addItem(TradeMarkVO.purstMark(result.Data[i]));
				}
				model.tradeMarks	=	marks;
				
				var result:XML		=	event.result.tradeSecrets[0];
				var secrets:ArrayCollection	=	new ArrayCollection();
				for(var i:int=0; i<result.Data.length(); i++)
				{
					secrets.addItem(TradeSecretVO.purseSecret(result.Data[i]));
				}
				model.tradeSecrets	=	secrets;
			}
			catch(error:Error)
			{
				
			}
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			model.result	=	"Program error";	
			model.bSubmit	=	true;
			trace(event.fault);
		}

	}
}